home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tcl / dist6.3 / tests / exec.test < prev    next >
Encoding:
Text File  |  1992-04-28  |  6.2 KB  |  182 lines

  1. # Commands covered:  exec
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /user6/ouster/tcl/tests/RCS/exec.test,v 1.17 92/04/28 10:01:37 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. # Basic operations.
  21.  
  22. test exec-1.1 {basic exec operation} {
  23.     exec echo a b c
  24. } "a b c"
  25. test exec-1.2 {pipelining} {
  26.     exec echo a b c d | cat | cat
  27. } "a b c d"
  28. test exec-1.3 {pipelining} {
  29.     set a [exec echo a b c d | cat | wc]
  30.     list [scan $a "%d %d %d" b c d] $b $c $d
  31. } {3 1 4 8}
  32.  
  33. # I/O redirection: input from Tcl command.
  34.  
  35. test exec-2.1 {redirecting input from immediate source} {
  36.     exec cat << "Sample text"
  37. } {Sample text}
  38. test exec-2.2 {redirecting input from immediate source} {
  39.     exec << "Sample text" cat | cat
  40. } {Sample text}
  41. test exec-2.3 {redirecting input from immediate source} {
  42.     exec cat << "Sample text" | cat
  43. } {Sample text}
  44. test exec-2.4 {redirecting input from immediate source} {
  45.     exec  cat | cat << "Sample text"
  46. } {Sample text}
  47.  
  48. # I/O redirection: output to file.
  49.  
  50. catch [exec rm -f gorp.file]
  51. test exec-3.1 {redirecting output to file} {
  52.     exec echo "Some simple words" > gorp.file
  53.     exec cat gorp.file
  54. } "Some simple words"
  55. test exec-3.2 {redirecting output to file} {
  56.     exec echo "More simple words" | > gorp.file cat | cat
  57.     exec cat gorp.file
  58. } "More simple words"
  59. test exec-3.3 {redirecting output to file} {
  60.     exec > gorp.file echo "Different simple words" | cat | cat
  61.     exec cat gorp.file
  62. } "Different simple words"
  63.  
  64. # I/O redirection: input from file.
  65.  
  66. exec echo "Just a few thoughts" > gorp.file
  67. test exec-4.1 {redirecting input from file} {
  68.     exec cat < gorp.file
  69. } {Just a few thoughts}
  70. test exec-4.2 {redirecting input from file} {
  71.     exec cat | cat < gorp.file
  72. } {Just a few thoughts}
  73. test exec-4.3 {redirecting input from file} {
  74.     exec cat < gorp.file | cat
  75. } {Just a few thoughts}
  76. test exec-4.4 {redirecting input from file} {
  77.     exec < gorp.file cat | cat
  78. } {Just a few thoughts}
  79.  
  80. # I/O redirection: combinations.
  81.  
  82. catch {exec rm -f gorp.file2}
  83. test exec-5.1 {multiple I/O redirections} {
  84.     exec << "command input" > gorp.file2 cat < gorp.file
  85.     exec cat gorp.file2
  86. } {Just a few thoughts}
  87. test exec-5.2 {multiple I/O redirections} {
  88.     exec < gorp.file << "command input" cat
  89. } {command input}
  90.  
  91. # Long input to command and output from command.
  92.  
  93. set a "0123456789 xxxxxxxxx abcdefghi ABCDEFGHIJK\n"
  94. set a [concat $a $a $a $a]
  95. set a [concat $a $a $a $a]
  96. set a [concat $a $a $a $a]
  97. set a [concat $a $a $a $a]
  98. test exec-6.1 {long input and output} {
  99.     exec cat << $a
  100. } $a
  101.  
  102. # Commands that return errors.
  103.  
  104. test exec-7.1 {commands returning errors} {
  105.     set x [catch {exec gorp456} msg]
  106.     list $x $msg [lindex $errorCode 0] [lrange $errorCode 2 end]
  107. } {1 {couldn't find "gorp456" to execute} CHILDSTATUS 1}
  108. test exec-7.2 {commands returning errors} {
  109.     set x [catch {exec foo123 | gorp456} msg]
  110.     set x1 {couldn't find "foo123" to execute
  111. couldn't find "gorp456" to execute}
  112.     set x2 {couldn't find "gorp456" to execute
  113. couldn't find "foo123" to execute}
  114.     set y [expr {($msg == $x1) || ($msg == $x2)}]
  115.     list $x $y [lindex $errorCode 0] [lrange $errorCode 2 end]
  116. } {1 1 CHILDSTATUS 1}
  117. test exec-7.3 {commands returning errors} {
  118.     list [catch {exec sleep 1 | sh -c "exit 43" | sleep 1} msg] $msg
  119. } {1 {}}
  120. test exec-7.4 {commands returning errors} {
  121.     list [catch {exec gorp456 | echo a b c} msg] $msg
  122. } {1 {a b c
  123. couldn't find "gorp456" to execute}}
  124.  
  125. # Errors in executing the Tcl command, as opposed to errors in the
  126. # processes that are invoked.
  127.  
  128. test exec-8.1 {errors in exec invocation} {
  129.     list [catch {exec} msg] $msg
  130. } {1 {didn't specify command to execute}}
  131. test exec-8.2 {errors in exec invocation} {
  132.     list [catch {exec | cat} msg] $msg
  133. } {1 {illegal use of | in command}}
  134. test exec-8.3 {errors in exec invocation} {
  135.     list [catch {exec cat |} msg] $msg
  136. } {1 {illegal use of | in command}}
  137. test exec-8.4 {errors in exec invocation} {
  138.     list [catch {exec cat | | cat} msg] $msg
  139. } {1 {illegal use of | in command}}
  140. test exec-8.5 {errors in exec invocation} {
  141.     list [catch {exec cat <} msg] $msg
  142. } {1 {can't specify "<" as last word in command}}
  143. test exec-8.6 {errors in exec invocation} {
  144.     list [catch {exec cat >} msg] $msg
  145. } {1 {can't specify ">" as last word in command}}
  146. test exec-8.7 {errors in exec invocation} {
  147.     list [catch {exec cat <<} msg] $msg
  148. } {1 {can't specify "<<" as last word in command}}
  149. test exec-8.8 {errors in exec invocation} {
  150.     list [catch {exec cat < a/b/c} msg] [string tolower $msg]
  151. } {1 {couldn't read file "a/b/c": no such file or directory}}
  152. test exec-8.9 {errors in exec invocation} {
  153.     list [catch {exec cat << foo > a/b/c} msg] [string tolower $msg]
  154. } {1 {couldn't write file "a/b/c": no such file or directory}}
  155.  
  156. # Commands in background.
  157.  
  158. test exec-9.1 {commands in background} {
  159.     set x [lindex [time {exec sleep 5 &}] 0]
  160.     expr $x<1000000
  161. } 1
  162. test exec-9.2 {commands in background} {
  163.     list [catch {exec echo a &b} msg] $msg
  164. } {0 {a &b}}
  165.  
  166. # Make sure "errorCode" is set correctly.
  167.  
  168. test exec-10.1 {setting errorCode variable} {
  169.     list [catch {exec cat < a/b/c} msg] [string tolower $errorCode]
  170. } {1 {unix enoent {no such file or directory}}}
  171. test exec-10.2 {setting errorCode variable} {
  172.     list [catch {exec cat > a/b/c} msg] [string tolower $errorCode]
  173. } {1 {unix enoent {no such file or directory}}}
  174. test exec-10.3 {setting errorCode variable} {
  175.     set x [catch {exec _weirdo_command_} msg]
  176.     list $x $msg [lindex $errorCode 0] [lrange $errorCode 2 end]
  177. } {1 {couldn't find "_weirdo_command_" to execute} CHILDSTATUS 1}
  178.  
  179. catch {exec rm -f gorp.file}
  180. catch {exec rm -f gorp.file2}
  181. return {}
  182.